package com.hertz.appr.pojo.db;

import java.util.Date;

import org.springframework.web.util.HtmlUtils;

import com.hertz.appr.util.Util;


/**
 * Message entity. @author MyEclipse Persistence Tools
 */

public class Message implements Comparable<Message> ,java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 4184567680565504125L;
	private Long id;
	private String tid;
	private String sourceTid;
	private String uid;
	private String nick;
	private String origtext;
	private Short type;
	private String value;
	private Long actionId;
	private String provider;
	private Long createTime;
	private Long systemTime;
	private Message sourceTwitter;
	private Boolean deleteFlag;
	
	public final static Boolean deleteFlagTrue = true;
	public final static Boolean deleteFlagFalse = false;
	
	/*
	 * 评论
	 */
	public final static Short type_comment = 7;
	/*
	 * 原创发表
	 */
	public final static Short type_original = 1;
	/*
	 * 转载
	 */
	public final static Short type_repost = 2;
	/*
	 * 私信
	 */
	public final static Short type_private = 3;
	/*
	 * 对话
	 */
	public final static Short type_reply = 4;


	// Constructors

	/** default constructor */
	public Message() {
	}

	/** minimal constructor */
	public Message(Long id, String tid, String uid, String nick,
			String origtext, Short type, String provider, Long createTime,
			Long systemTime) {
		this.id = id;
		this.tid = tid;
		this.uid = uid;
		this.nick = nick;
		this.origtext = origtext;
		this.type = type;
		this.provider = provider;
		this.createTime = createTime;
		this.systemTime = systemTime;
	}

	/** full constructor */
	public Message(Long id, String tid, String sourceTid, String uid,
			String nick, String origtext, Short type, String value,
			Long actionId, String provider, Long createTime, Long systemTime) {
		this.id = id;
		this.tid = tid;
		this.sourceTid = sourceTid;
		this.uid = uid;
		this.nick = nick;
		this.origtext = origtext;
		this.type = type;
		this.value = value;
		this.actionId = actionId;
		this.provider = provider;
		this.createTime = createTime;
		this.systemTime = systemTime;
	}

	// Property accessors

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTid() {
		return this.tid;
	}

	public void setTid(String tid) {
		this.tid = tid;
	}

	public String getSourceTid() {
		return this.sourceTid;
	}

	public void setSourceTid(String sourceTid) {
		this.sourceTid = sourceTid;
	}

	public String getUid() {
		return this.uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public String getNick() {
		return this.nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public String getOrigtext() {
		return origtext;
	}
	public String getOrigtextEscape() {
		return HtmlUtils.htmlEscape(origtext).replace("<", "&lt;").replace(">", "&gt;");
	}
	public void setOrigtext(String origtext) {
		this.origtext = origtext;
	}

	public Short getType() {
		return this.type;
	}

	public void setType(Short type) {
		this.type = type;
	}

	public String getValue() {
		return this.value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Long getActionId() {
		return this.actionId;
	}

	public void setActionId(Long actionId) {
		this.actionId = actionId;
	}

	public String getProvider() {
		return this.provider;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public Long getCreateTime() {
		return Util.timestamp10to13(this.createTime);
	}
	public Long getCreateTimeShort(){
		return this.createTime;
	}
	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	public Long getSystemTime() {
		return this.systemTime;
	}

	public void setSystemTime(Long systemTime) {
		this.systemTime = systemTime;
	}
	public Message getSourceTwitter() {
		return sourceTwitter;
	}

	public void setSourceTwitter(Message sourceTwitter) {
		this.sourceTwitter = sourceTwitter;
	}

	@Override
	public String toString(){
		return "Message{" +
		" provider=" + String.format("%1$4S", provider) +
		", uid=" + String.format("%1$-20S", uid) +
		", tid=" + String.format("%1$-20S", tid) +
        ", nick=" + String.format("%1$-20S", this.nick) +
        ", value=" + String.format("%1$-20S", this.value) +
        ", create_time='" + this.createTime + '\'' +
        ", type=" + String.format("%1$-3S", this.type) +
        ", origtext='" + origtext + '\'' +
        '}';
	}

	@Override
	public int compareTo(Message o) {
		// TODO Auto-generated method stub
		if(this == o)
			return 0;
		return Long.valueOf(this.createTime).compareTo(o.getCreateTimeShort());
	}
	public String getCreateTimeStr(){
		String str = "";
		try {
			str = Util.parseDate(new Date(getCreateTime()), "yyyy-MM-dd HH:mm:ss");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return str;
	}

	public Boolean getDeleteFlag() {
		return deleteFlag;
	}

	public void setDeleteFlag(Boolean deleteFlag) {
		this.deleteFlag = deleteFlag;
	}
}